package com.qezhhnjy.mall.product.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qezhhnjy.mall.common.entity.product.AttrGroup;
import com.qezhhnjy.mall.common.http.BaseResult;
import com.qezhhnjy.mall.product.service.AttrGroupService;
import io.swagger.annotations.Api;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 属性分组 前端控制器
 * </p>
 *
 * @author qezhhnjy
 * @since 2021-06-27
 */
@RestController
@Api(tags = "属性分组接口")
@Slf4j
@RequestMapping("/attr-group")
public class AttrGroupController {
    @Resource
    private AttrGroupService attrGroupService;

    @GetMapping("/get")
    @Operation(summary = "根据id获取属性分组信息")
    public BaseResult<AttrGroup> get(Long id) {
        AttrGroup attrGroup = attrGroupService.getById(id);
        return BaseResult.success(attrGroup);
    }

    @PostMapping("/save")
    @Operation(summary = "新增属性分组信息")
    public BaseResult<AttrGroup> save(@RequestBody AttrGroup attrGroup) {
        attrGroupService.save(attrGroup);
        return BaseResult.success(attrGroup);
    }

    @PutMapping("/update")
    @Operation(summary = "更新属性分组信息")
    public BaseResult<AttrGroup> update(@RequestBody AttrGroup attrGroup) {
        attrGroupService.updateById(attrGroup);
        return BaseResult.success(attrGroup);
    }

    @PostMapping("/page")
    @Operation(summary = "分页获取属性分组信息")
    public BaseResult<Page<AttrGroup>> page(@RequestBody Page<AttrGroup> page) {
        attrGroupService.page(page);
        return BaseResult.success(page);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "根据id删除属性分组信息")
    public BaseResult<Long> delete(Long id) {
        attrGroupService.removeById(id);
        return BaseResult.success(id);
    }
}

